function loadImage(url) {
	var img = new Image(); 
	// 创建一个Image对象，实现图片的预下载
	img.src = url;
	if (img.complete) {
		return img.src;
	}
	img.onload = function () {
		return img.src;
	};
};

/* 时间格式化 */
Date.prototype.format = function(format) {
    var date = {
           "M+": this.getMonth() + 1,
           "d+": this.getDate(),
           "h+": this.getHours(),
           "m+": this.getMinutes(),
           "s+": this.getSeconds(),
           "q+": Math.floor((this.getMonth() + 3) / 3),
           "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
           format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
           if (new RegExp("(" + k + ")").test(format)) {
                  format = format.replace(RegExp.$1, RegExp.$1.length == 1
                         ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
           }
    }
    return format;
}

/* 刷新当前页面 */
function replace(){
	location.replace(location.href);
}

function tabLanguage(language){
	if(language && $.cookie("language") != language){
		var date = new Date();  
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000)); // 365天后的这个时候过期
		$.cookie("language",language, { path: ctx+'/', expires: date });
		replace();
	}
}

/**
 * 获取当前页面目录
 */
 function getUrlPath(){  
　var url = document.location.toString();               
　if(url.indexOf("/") != -1){  
         url = url.substring(0,  url.lastIndexOf("/")+1) ;  
　}  
　return url;  
}  

 /**
	 * 获取当前js路径
	 */
 function getJsUrlPath(){
	return window.UEDITOR_HOME_URL || getUEBasePath();
 }
 
 
 
 function getUEBasePath(docUrl, confUrl) {
     return getBasePath(docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath());
 }
 
 function getConfigFilePath() {
     var configPath = document.getElementsByTagName('script');
     return configPath[ configPath.length - 1 ].src;
 }

 function getBasePath(docUrl, confUrl) {
     var basePath = confUrl;
     if (/^(\/|\\\\)/.test(confUrl)) {
         basePath = /^.+?\w(\/|\\\\)/.exec(docUrl)[0] + confUrl.replace(/^(\/|\\\\)/, '');
     } else if (!/^[a-z]+:/i.test(confUrl)) {
         docUrl = docUrl.split("#")[0].split("?")[0].replace(/[^\\\/]+$/, '');
         basePath = docUrl + "" + confUrl;
     }
     return optimizationPath(basePath);
 }

 function optimizationPath(path) {
     var protocol = /^[a-z]+:\/\//.exec(path)[ 0 ],
         tmp = null,
         res = [];
     path = path.replace(protocol, "").split("?")[0].split("#")[0];
     path = path.replace(/\\/g, '/').split(/\//);
     path[ path.length - 1 ] = "";
     while (path.length) {
         if (( tmp = path.shift() ) === "..") {
             res.pop();
         } else if (tmp !== ".") {
             res.push(tmp);
         }
     }
     return protocol + res.join("/");
 }
 
 
 $.extend({
	 include: function(url,file) {
		 var files = typeof file == "string" ? [file]:file;
		 for (var i = 0; i < files.length; i++) {
			 var name = files[i];
			 var att = name.split('.');
			 var ext = att[att.length - 1].toLowerCase();
			 var isCSS = ext == "css";
			 var tag = isCSS ? "link" : "script";
			 var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
			 var link = (isCSS ? "href" : "src") + "='" + url + name + "'";
			 if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
		 }
	 }
});
 
 $(function(){
     $("body").on("click","[url]",function(){
     	if($(this).attr("url")){
     		window.location.href=$(this).attr("url");
     	}
     }).on("click",".lang",function(){
    	 var language = $(this).attr("lang");
    	 tabLanguage(language);
     });
     
    var lang = $(".lang[lang="+lang+"]");
	var prevs = lang.prevAll();
	lang.removeClass("lang");
	if(prevs.length){
		prevs.eq(prevs.length-1).before(lang);
	}
 })